package com.hzdl.hotel.controller;

import com.hzdl.hotel.bean.Statistics;
import com.hzdl.hotel.service.StatisticsService;
import com.hzdl.hotel.util.AJAXResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService ss;


    @RequestMapping("/leftShow")
    public String leftShow(){
        return "administer/statistics/district";
    }

    @RequestMapping("/rightShow")
    public String rightShow(){
        return "administer/statistics/preference";
    }

    @RequestMapping("/leftDistrictShow")
    @ResponseBody
    public AJAXResult leftDistrictShow(){
        List<Statistics> sList=ss.findDistrict();
        return new AJAXResult(1,sList);
    }

    @RequestMapping("/rightPreferenceShow")
    @ResponseBody
    public AJAXResult rightPreferenceShow(){
        List<Statistics> sList=ss.findPreference();
        return new AJAXResult(1,sList);
    }

    @RequestMapping("/revenue")
    public String revenue(){
        return "administer/statistics/revenue";
    }

    @RequestMapping("/revenueShow")
    @ResponseBody
    public AJAXResult revenueShow(Integer year){
     List<Statistics> sList= ss.findSum(year);
        Map<String,Object> map=new HashMap<>();
       List<String> name=new ArrayList<>();
       List<String> value=new ArrayList<>();
     for(Statistics s:sList){
         name.add(s.getName());
         value.add(s.getValue());
     }
       map.put("name",name);
     map.put("value",value);
     return new AJAXResult(1,map);
    }
}
